//
//  ManipulatorViewController.m
//  Utils
//
//  Created by enghou on 2018/4/18.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "ManipulatorViewController.h"
#import "ManipulatorItemModel.h"
@interface ManipulatorViewController ()

@end

@implementation ManipulatorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"主办单位";
    self.tableView.allowsMultipleSelection = NO;
    self.tableView.editing = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(sure)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
}

-(NSDictionary *)param{
    return @{@"issueStepId":self.stepId,@"page":[NSString stringWithFormat:@"%i",self.page],@"rows":@"10"};
}

-(void)sure{
    if ([self.theDelete respondsToSelector:@selector(fetchModel:)]) {
        NSArray *cells = [self.tableView indexPathsForSelectedRows];
        if ([cells count] > 0) {
            NSMutableArray *ret = [NSMutableArray array];
            for (NSIndexPath *path in cells) {
                NSInteger row = path.row;
                [ret addObject:self.source[row]];
            }
            [self.theDelete fetchModel:ret[0]];
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        [self alertSome:@"请选择主办单位!"];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    ManipulatorItemModel *model = [self.source objectAtIndex:indexPath.row];
    cell.textLabel.text = model.name;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}

@end
